home *** CD-ROM | disk | FTP | other *** search
- /*-----------------------------------------------------------------------------
- - File Name:
- - Edit PayPal Single Item Purchase.js
- -
- - Description:
- - Functions for PayPal Single Item Purchase Advanced Mode.
- -
- - This file contains proprietary and confidential information from WebAssist.com
- - corporation. Any unauthorized reuse, reproduction, or modification without
- - the prior written consent of WebAssist.com is strictly prohibited.
- -
- - Copyright 2001 WebAssist.com Corporation. All rights reserved.
- ------------------------------------------------------------------------------*/
- var CURRENTPAGE = 0;
- var INSPECTIONPARAMS = false;
- var INTERFACE = "advanced";
- var theOrig ="";
-
- function commandButtons() {
- return new Array();
- }
-
- function displayHelp() {
- INTERFACE = "advanced";
- displayContextHelp();
- }
-
- function receiveArguments(charttype, ssRec, paramString) {
- INSPECTIONPARAMS = true;
- }
-
- /* Initialize the UI. First thing that's called on the body load event. */
- function initializeUI() {
- MM.setBusyCursor();
- if (navigator.platform.toLowerCase().indexOf("mac") >= 0) {
- document.background.document.tabBgWin.src = "../Shared/PayPal/images/AdvancedBG_Mac.gif";
- document.Tab0.document.tabBG.src = "../Shared/PayPal/images/tabBg_Mac.gif";
- document.Tab1.document.tabBG.src = "../Shared/PayPal/images/longTabBg_Mac.gif";
- document.Tab2.document.tabBG.src = "../Shared/PayPal/images/longTabBg_Mac.gif";
- document.Tab3.document.tabBG.src = "../Shared/PayPal/images/longTabBg_Mac.gif";
- document.background.style = "top:23px;";
-
- document.cancel.style = "position:absolute; width:70px; height:20px; z-index:94; left: 310px; top: 373px; visibility: visible";
- document.cancel.document.btnCancel.style = "width:63; height:20; font-family:'Lucidia Grande'; font-size: 13px";
-
- document.OK.style = "position:absolute; width:70px; height:20px; z-index:94; left: 380px; top: 373px; visibility: visible";
- document.OK.document.btnOK.style = "width:63; height:20; font-family:'Lucidia Grande'; font-size: 13px";
-
- document.help.style = "position:absolute; width:70px; height:20px; z-index:94; left: 240px; top: 373px; visibility: visible";
- document.help.document.btnHelp.style = "width:63; height:20; font-family:'Lucidia Grande'; font-size: 13px";
-
- document.walogo.top = 375;
- document.pplogo.top = 376;
- }
- document.OK.visibility = "visible";
- document.cancel.visibility = "visible";
- document.help.visibility = "visible";
- document.background.visibility = "visible";
- document.Tab0.visibility = "visible";
- document.Tab1.visibility = "visible";
- document.Tab2.visibility = "visible";
- document.Tab3.visibility = "visible";
- // Get values from the inspected node and populate our UI accordingly
- var theDOM = dw.getDocumentDOM();
- var theSelection = theDOM.getSelectedNode();
- theOrig = unescape(theSelection.orig);
- while (theSelection.tagName!="FORM" && theSelection.parentNode && theSelection.PPwholeForm != "true") {
- theSelection = theSelection.parentNode;
- }
- theOrig = theSelection.outerHTML;
- var tempOrig = theOrig;
- var firstInput = findOpenTag(tempOrig,"input");
- while (firstInput != "")
- {
- var inputName = getTagProp(firstInput,"input","name");
- var theVal = getTagProp(firstInput,"input","value");
- switch (inputName.toLowerCase())
- {
- case "business":
- if (theVal != "")
- document.generalWP.document.ppUID.value = theVal;
- break;
-
- case "item_name":
- if (theVal != "")
- document.itemWP.document.itemName.value = theVal;
- break;
-
- case "item_number":
- if (theVal != "")
- document.itemWP.document.itemID.value = theVal;
- break;
-
- case "amount":
- if (theVal != "")
- document.itemWP.document.itemPrice.value = theVal;
- break;
-
- case "currency_code":
- var theCurrency = document.itemWP.document.itemCurrency;
- for (var n=0; n<theCurrency.options.length; n++)
- {
- if (theVal == theCurrency.options[n].value)
- {
- theCurrency.selectedIndex = n;
- break;
- }
- }
- break;
-
- case "shipping":
- if (theVal != "")
- document.shippingWP.document.itemShipping.value = theVal;
- break;
-
- case "shipping2":
- if (theVal != "")
- document.shippingWP.document.itemShipping2.value = theVal;
- break;
-
- case "handling":
- if (theVal != "")
- document.shippingWP.document.itemHandling.value = theVal;
- break;
-
- case "image_url":
- if (isValidURL(theVal))
- document.generalWP.document.ppLogo.value = theVal;
- break;
-
- case "return":
- if (isValidURL(theVal))
- document.generalWP.document.successURL.value = theVal;
- break;
-
- case "cancel_return":
- if (isValidURL(theVal))
- document.generalWP.document.cancelURL.value = theVal;
- break;
-
- case "undefined_quantity":
- if (theVal == "1")
- {
- document.itemWP.document.quantityYes.checked = true;
- }
- break;
-
- case "no_shipping":
- if (theVal == "1")
- {
- document.shippingWP.document.shippingNo[1].checked = true;
- }
- break;
-
- case "no_note":
- if (theVal == "1")
- {
- document.shippingWP.document.includeNote[1].checked = true;
- }
- break;
-
- case "submit": // button image URL
- var theImg = document.buttonWP.document.sipimage;
- theVal = getTagProp(firstInput,"input","src");
- var myImage = getTranslatedSIPImage(theVal);
- if (myImage == CUSTOM_SIP_IMG)
- {
- myImage = "other";
- document.buttonWP.document.othersipimage.value = theVal;
- }
-
- for (var n=0; n<theImg.length; n++)
- {
- if (myImage == theImg[n].value)
- {
- theImg[n].checked = true;
- }
- else
- {
- theImg[n].checked = false;
- }
- }
- break;
-
- default:
- break;
- }
-
- tempOrig = tempOrig.substring(tempOrig.indexOf(firstInput)+firstInput.length);
- firstInput = findOpenTag(tempOrig,"input");
-
- }
-
- enableDisableOtherImage();
-
- // Go to the item details page
- showPageNum(2);
-
- MM.clearBusyCursor();
-
- return true;
- }
-
- /******************************** support functions ******************/
- function generateSIP()
- {
- var myErrors = validateUI();
- if (myErrors == "")
- {
- updateSIP(theOrig);
- }
- else
- {
- alert (myErrors);
- }
-
- return;
- }
-
- function updateSIP(formTag) {
- var theForm = formTag;
- var undefinedQty = (document.itemWP.document.quantityYes.checked)?"1":"0";
- var theBusiness = document.generalWP.document.ppUID.value;
- var theItemName = document.itemWP.document.itemName.value;
- var theItemNumber = document.itemWP.document.itemID.value;
- var theAmount = document.itemWP.document.itemPrice.value;
- var theShipping = document.shippingWP.document.itemShipping.value
- var theShipping2 = document.shippingWP.document.itemShipping2.value
- var theHandling = document.shippingWP.document.itemHandling.value
- var theCurrencyCode = document.itemWP.document.itemCurrency.options[document.itemWP.document.itemCurrency.selectedIndex].value;
- var theImageURL = document.generalWP.document.ppLogo.value;
- var theReturn = document.generalWP.document.successURL.value;
- var theCancel = document.generalWP.document.cancelURL.value
- var theNoShip = (document.shippingWP.document.shippingNo[0].checked)?"0":"1";
- var theNoNote = (document.shippingWP.document.includeNote[1].checked)?"1":"0";
- var theButtonImage = document.buttonWP.document.sipimage[0].value;
-
- if (theImageURL == "https://" || theImageURL == "http://")
- theImageURL = "";
- if (theReturn == "https://" || theReturn == "http://")
- theReturn = "";
- if (theCancel == "https://" || theCancel == "http://")
- theCancel = "";
-
- for (x in document.buttonWP.document.sipimage) {
- if (document.buttonWP.document.sipimage[x].checked)
- theButtonImage = document.buttonWP.document.sipimage[x].value;
- }
- if (theButtonImage == "other")
- theButtonImage = document.buttonWP.document.othersipimage.value;
- else
- theButtonImage = "http://images.paypal.com/images/" + theButtonImage;
- theForm = updateFormInput(theForm,"business",theBusiness);
- theForm = updateFormInput(theForm,"undefined_quantity",undefinedQty);
- theForm = updateFormInput(theForm,"item_name",theItemName);
- theForm = updateFormInput(theForm,"item_number",theItemNumber);
- theForm = updateFormInput(theForm,"amount",theAmount);
- theForm = updateFormInput(theForm,"shipping",theShipping);
- theForm = updateFormInput(theForm,"shipping2",theShipping2);
- theForm = updateFormInput(theForm,"handling",theHandling);
- theForm = updateFormInput(theForm,"currency_code",theCurrencyCode);
- theForm = updateFormInput(theForm,"image_url",theImageURL);
- theForm = updateFormInput(theForm,"return",theReturn);
- theForm = updateFormInput(theForm,"cancel_return",theCancel);
- theForm = updateFormInput(theForm,"no_shipping",theNoShip);
- theForm = updateFormInput(theForm,"no_note",theNoNote);
- theForm = updateFormInput(theForm,"bn",BNVersion);
- theForm = updateImage(theForm,theButtonImage);
- var theDOM = dreamweaver.getDocumentDOM();
- var thePage = theDOM.documentElement.outerHTML;
- var theSelection = theDOM.getSelectedNode();
- var theOffsets = new Array();
- while (theSelection.tagName!="FORM" && theSelection.PPwholeForm!="true") {
- theSelection = theSelection.parentNode;
- }
- theDOM.setSelectedNode(theSelection);
- theDOM.insertHTML(theForm);
- closeWindow();
- }
-
- function updateImage(formHTML,image) {
- var theInput = /<input\s[^<]*type=(['"])image\1/i;
- if (formHTML.search(theInput)>=0) {
- var theTag = findOpenTag(formHTML.substring(formHTML.search(theInput)),"input");
- formHTML = formHTML.substring(0,formHTML.indexOf(theTag)) + updateTagProp(theTag,"input","src",image) + formHTML.substring(formHTML.indexOf(theTag)+theTag.length);
- }
- else {
- formHTML = formHTML.substring(0,formHTML.search(/\s*<\/form>/i))+'\r\n<input type="image" name="submit" src="'+image+'" border="0" alt="Make payments with PayPal - it\'s fast, free and secure!">'+formHTML.substring(formHTML.search(/\s*<\/form>/i));
- }
- return formHTML;
- }
-
- function updateFormInput(formHTML,fieldName,fieldValue) {
- var theInput = new RegExp('<input\\s[^<]*name=([\'"]?)'+fieldName+'\\1',"i");
- if (formHTML.search(theInput)>=0) {
- var theTag = findOpenTag(formHTML.substring(formHTML.search(theInput)),"input");
- if (fieldValue!="")
- formHTML = formHTML.substring(0,formHTML.indexOf(theTag)) + updateTagProp(theTag,"input","value",fieldValue) + formHTML.substring(formHTML.indexOf(theTag)+theTag.length);
- else
- formHTML = formHTML.substring(0,formHTML.indexOf(theTag)) + formHTML.substring(formHTML.indexOf(theTag)+theTag.length);
- }
- else {
- if (fieldValue!="")
- formHTML = formHTML.substring(0,formHTML.search(/\s*<\/form>/i))+'\r\n<input type="hidden" name="'+fieldName+'" value="'+fieldValue+'">'+formHTML.substring(formHTML.search(/\s*<\/form>/i));
- }
- return formHTML;
- }
-
-
-
- function validateUI() {
- var errMsg = "";
- var tempErrMsg = "";
- var myAmount = document.itemWP.document.itemPrice.value;
- var myShipping = document.shippingWP.document.itemShipping.value;
- var myShipping2 = document.shippingWP.document.itemShipping2.value;
- var myHandling = document.shippingWP.document.itemHandling.value;
- var accountErrMsg = validatePPUID();
- if (accountErrMsg != "")
- {
- errMsg += "PayPal Account " + accountErrMsg;
- }
-
- if (myAmount != "")
- {
- tempErrMsg = validateItemPrice(myAmount);
- if (tempErrMsg != "")
- {
- errMsg += "Item Price " + tempErrMsg;
- }
- }
-
- if (myShipping != "")
- {
- tempErrMsg = validateAmount(myShipping);
- if (tempErrMsg != "")
- {
- errMsg += "Base Shipping " + tempErrMsg;
- }
- }
-
- if (myShipping2 != "")
- {
- tempErrMsg = validateAmount(myShipping2);
- if (tempErrMsg != "")
- {
- errMsg += "Extra Shipping " + tempErrMsg;
- }
- }
-
- if (myHandling != "")
- {
- tempErrMsg = validateAmount(myHandling);
- if (tempErrMsg != "")
- {
- errMsg += "Handling " + tempErrMsg;
- }
- }
-
- if ( errMsg != "" )
- {
- errMsg = "The following errors were found:\n\n" + errMsg;
- }
-
- return errMsg;
- }
-
- function enableDisableOtherImage() {
- var myImage = document.buttonWP.document.sipimage;
- for (var n=0; n<myImage.length; n++)
- {
- if (myImage[n].checked)
- {
- if (myImage[n].value == "other")
- {
- document.buttonWP.document.othersipimage.disabled = "enabled";
- }
- else
- {
- document.buttonWP.document.othersipimage.disabled = "disabled";
- }
- }
- }
- }
-
- /******************************** PAGE FUNCTIONS ********************************/
- function Pg0_Load() {
- document.generalWP.visibility = "visible";
- setTimeout("document.generalWP.document.ppUID.focus()",500);
- return true;
- }
- function Pg0_unLoad() {
- document.generalWP.visibility = "hidden";
- document.generalWP.visibility = "visible";
- document.generalWP.visibility = "hidden";
- return true;
- }
-
- function Pg1_Load() {
- document.buttonWP.visibility = "visible";
- return true;
- }
- function Pg1_unLoad() {
- document.buttonWP.visibility = "hidden";
- document.buttonWP.visibility = "visible";
- document.buttonWP.visibility = "hidden";
- return true;
- }
-
- function Pg2_Load() {
- document.itemWP.visibility = "visible";
- setTimeout("document.itemWP.document.itemName.focus()",500);
- return true;
- }
- function Pg2_unLoad() {
- document.itemWP.visibility = "hidden";
- document.itemWP.visibility = "visible";
- document.itemWP.visibility = "hidden";
- return true;
- }
-
- function Pg3_Load() {
- document.shippingWP.visibility = "visible";
- setTimeout("document.shippingWP.document.itemShipping.focus()",500);
- return true;
- }
- function Pg3_unLoad() {
- document.shippingWP.visibility = "hidden";
- document.shippingWP.visibility = "visible";
- document.shippingWP.visibility = "hidden";
- return true;
- }
-
- function showPageNum(pageNum) {
- eval("Pg"+CURRENTPAGE+"_unLoad()");
- if (navigator.platform.toLowerCase().indexOf("mac") >= 0) {
- eval("document.Tab"+CURRENTPAGE+".document.tabBG.src = document.Tab"+CURRENTPAGE+".document.tabBG.src.substring(0,document.Tab"+CURRENTPAGE+".document.tabBG.src.toLowerCase().lastIndexOf('tabbg'))+'tabBg_Mac.gif'");
- }
- else {
- eval("document.Tab"+CURRENTPAGE+".document.tabBG.src = document.Tab"+CURRENTPAGE+".document.tabBG.src.substring(0,document.Tab"+CURRENTPAGE+".document.tabBG.src.toLowerCase().lastIndexOf('tabbg'))+'tabBg.gif'");
- }
- CURRENTPAGE = pageNum;
- if (navigator.platform.toLowerCase().indexOf("mac") >= 0) {
- eval("document.Tab"+CURRENTPAGE+".document.tabBG.src = document.Tab"+CURRENTPAGE+".document.tabBG.src.substring(0,document.Tab"+CURRENTPAGE+".document.tabBG.src.toLowerCase().lastIndexOf('tabbg'))+'tabBgSel_Mac.gif'");
- }
- else {
- eval("document.Tab"+CURRENTPAGE+".document.tabBG.src = document.Tab"+CURRENTPAGE+".document.tabBG.src.substring(0,document.Tab"+CURRENTPAGE+".document.tabBG.src.toLowerCase().lastIndexOf('tabbg'))+'tabBgSel.gif'");
- }
- eval("Pg"+CURRENTPAGE+"_Load()");
- }